<?php

namespace App\Models;

use App\Scopes\TeamLeaderScope;
use Illuminate\Database\Eloquent\Model;

class TeamLeader extends Model
{
    protected $fillable = ['username', 'password', 'name', 'avatar', 'team_id'];

    protected $table = 'admin_users';

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope(new TeamLeaderScope());
    }

    public function team()
    {
        return $this->belongsTo(Team::class, 'team_id');
    }

    public function dispatchFreeLogs()
    {
        return $this->hasMany(DispatchFreeLog::class, 'team_leader_id');
    }

    public function roles()
    {
        $pivotTable = config('admin.database.role_users_table');

        $relatedModel = config('admin.database.roles_model');

        return $this->belongsToMany($relatedModel, $pivotTable, 'user_id', 'role_id');
    }
}
